package de.jamm.aws;

import java.util.Observable;
import java.util.Observer;

import de.hshannover.inform.muehle.strategy.Strategy;
import de.jamm.gui.Log;
import de.jamm.msg.Msg;

public class Fassade extends Observable {
	private Game game;
	private static Fassade instance;
	private String player1;
	private String player2;
	
	public Fassade(){
		this.game = new Game();
		Fassade.instance = this;
		Field.newFields();
	}
	public void setPlayer1(String name1, int side1){
		game.setPlayer1(new Player(name1, (byte)side1, this.game));
		Log.d("System", "Spieler \""+name1+"\" vorbereiten..");
	}
	public void setPlayer2(String name2, int side2){
		game.setPlayer2(new Player(name2, (byte)side2, this.game));
		Log.d("System", "Spieler \""+name2+"\" vorbereiten..");
	}
	
	public void startGame(){
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				Field.newFields();
				game.startGame();
			}
		}).start();
		
		Log.n("Herzlich willkommen", "Viel Erfolg!", 3000);
	}
	
	public void setKI1(Strategy name){
		game.setKi1(name);
		Log.d("System", "KI \""+name.getStrategyName()+"\" laden..");
	}
	
	public void setKI2(Strategy name){
		game.setKi2(name);
		Log.d("System", "KI \""+name.getStrategyName()+"\" laden..");
	}
	
	public void move(int pos_old, int pos_new, int side){
		game.moveToken(new MuehleMove(pos_old, pos_new), side);
	}
	
	public void removeToken(int pos, int side){
		game.removeToken(pos, side);
	}
	
	public void addToken(int posOld,int pos, int side){
		game.addToken(posOld,pos, side);
	}
	
	public String getNamePlayer1(){
		return player1;
	}
	
	public String getNamePlayer2(){
		return player2;
	}
	
//Observer

	public void registObserver(Observer o){
		addObserver(o);
		Fassade.getInstance().setChanged();
		Fassade.getInstance().notifyObservers(new Msg(Msg.NEW_GAME, null));
	}
	public static Fassade getInstance() {
		return instance;
	}
	public static void setInstance(Fassade instance) {
		Fassade.instance = instance;
	}
	
	public void setThinkTime(int time){
		game.setThinkTime(time);
	}
	
	public void setWaitTime(int time){
		game.setWaitTime(time);
	}
}
